package com.hmall.api.fallback;

import com.hmall.api.client.ItemClient;
import com.hmall.api.domain.dto.ItemDTO;
import com.hmall.api.domain.dto.OrderDetailDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.Collection;
import java.util.List;

@Slf4j
public class ItemServiceFallback implements FallbackFactory<ItemClient> {
    @Override
    public ItemClient create(Throwable cause) {
        return new ItemClient() {
            @Override
            public List<ItemDTO> queryItemByIds(Collection<Long> ids) {
                log.info("库存服务异常");
                return null;
            }

            @Override
            public void deductStock(List<OrderDetailDTO> detailDTOs) {
                // 降级逻辑
                throw new RuntimeException("库存服务异常");
            }
        };
    }
}
